<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="活动编号" prop="activityNo">
        <el-select v-model="queryParams.activityNo" placeholder="请选择活动编号" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="推送编号" prop="pushNo">
        <el-input
          v-model="queryParams.pushNo"
          placeholder="请输入推送编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送时间类型" prop="pushTimeType">
        <el-select v-model="queryParams.pushTimeType" placeholder="请选择推送时间类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="推送时间" prop="pushTime">
        <el-input
          v-model="queryParams.pushTime"
          placeholder="请输入推送时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送起始日期" prop="pushStartDate">
        <el-input
          v-model="queryParams.pushStartDate"
          placeholder="请输入推送起始日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送结束日期" prop="pushEndDate">
        <el-input
          v-model="queryParams.pushEndDate"
          placeholder="请输入推送结束日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推送人群类型" prop="pushCrowdType">
        <el-select v-model="queryParams.pushCrowdType" placeholder="请选择推送人群类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="定向推广类型" prop="directPushType">
        <el-select v-model="queryParams.directPushType" placeholder="请选择定向推广类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="注册开始日期" prop="startRegisterDate">
        <el-input
          v-model="queryParams.startRegisterDate"
          placeholder="请输入注册开始日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="注册结束日期" prop="endRegisterDate">
        <el-input
          v-model="queryParams.endRegisterDate"
          placeholder="请输入注册结束日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户编号规则" prop="customerNoPattern">
        <el-input
          v-model="queryParams.customerNoPattern"
          placeholder="请输入用户编号规则"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户状态" prop="customerStatus">
        <el-select v-model="queryParams.customerStatus" placeholder="请选择用户状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建人" prop="buildOperator">
        <el-input
          v-model="queryParams.buildOperator"
          placeholder="请输入创建人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建日期" prop="buildDate">
        <el-input
          v-model="queryParams.buildDate"
          placeholder="请输入创建日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="buildTime">
        <el-input
          v-model="queryParams.buildTime"
          placeholder="请输入创建时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改人" prop="modifiedOperator">
        <el-input
          v-model="queryParams.modifiedOperator"
          placeholder="请输入修改人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改日期" prop="modifiedDate">
        <el-input
          v-model="queryParams.modifiedDate"
          placeholder="请输入修改日期"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="modifiedTime">
        <el-input
          v-model="queryParams.modifiedTime"
          placeholder="请输入修改时间"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['activity:push:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['activity:push:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['activity:push:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['activity:push:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pushList" @selection-change="handleSelectionChange" :border="true">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="活动编号" align="center" prop="activityNo" />
      <el-table-column label="推送编号" align="center" prop="pushNo" />
      <el-table-column label="推送时间类型" align="center" prop="pushTimeType" />
      <el-table-column label="推送时间" align="center" prop="pushTime" />
      <el-table-column label="推送起始日期" align="center" prop="pushStartDate" />
      <el-table-column label="推送结束日期" align="center" prop="pushEndDate" />
      <el-table-column label="推送人群类型" align="center" prop="pushCrowdType" />
      <el-table-column label="定向推广类型" align="center" prop="directPushType" />
      <el-table-column label="注册开始日期" align="center" prop="startRegisterDate" />
      <el-table-column label="注册结束日期" align="center" prop="endRegisterDate" />
      <el-table-column label="用户编号规则" align="center" prop="customerNoPattern" />
      <el-table-column label="用户状态" align="center" prop="customerStatus" />
      <el-table-column label="创建人" align="center" prop="buildOperator" />
      <el-table-column label="创建日期" align="center" prop="buildDate" />
      <el-table-column label="创建时间" align="center" prop="buildTime" />
      <el-table-column label="修改人" align="center" prop="modifiedOperator" />
      <el-table-column label="修改日期" align="center" prop="modifiedDate" />
      <el-table-column label="修改时间" align="center" prop="modifiedTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['activity:push:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['activity:push:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改活动推送对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="活动编号" prop="activityNo">
          <el-select v-model="form.activityNo" placeholder="请选择活动编号">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="推送编号" prop="pushNo">
          <el-input v-model="form.pushNo" placeholder="请输入推送编号" />
        </el-form-item>
        <el-form-item label="推送时间类型" prop="pushTimeType">
          <el-select v-model="form.pushTimeType" placeholder="请选择推送时间类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="推送时间" prop="pushTime">
          <el-input v-model="form.pushTime" placeholder="请输入推送时间" />
        </el-form-item>
        <el-form-item label="推送起始日期" prop="pushStartDate">
          <el-input v-model="form.pushStartDate" placeholder="请输入推送起始日期" />
        </el-form-item>
        <el-form-item label="推送结束日期" prop="pushEndDate">
          <el-input v-model="form.pushEndDate" placeholder="请输入推送结束日期" />
        </el-form-item>
        <el-form-item label="推送人群类型" prop="pushCrowdType">
          <el-select v-model="form.pushCrowdType" placeholder="请选择推送人群类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="定向推广类型" prop="directPushType">
          <el-select v-model="form.directPushType" placeholder="请选择定向推广类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="注册开始日期" prop="startRegisterDate">
          <el-input v-model="form.startRegisterDate" placeholder="请输入注册开始日期" />
        </el-form-item>
        <el-form-item label="注册结束日期" prop="endRegisterDate">
          <el-input v-model="form.endRegisterDate" placeholder="请输入注册结束日期" />
        </el-form-item>
        <el-form-item label="用户编号规则" prop="customerNoPattern">
          <el-input v-model="form.customerNoPattern" placeholder="请输入用户编号规则" />
        </el-form-item>
        <el-form-item label="用户状态">
          <el-radio-group v-model="form.customerStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="创建人" prop="buildOperator">
          <el-input v-model="form.buildOperator" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建日期" prop="buildDate">
          <el-input v-model="form.buildDate" placeholder="请输入创建日期" />
        </el-form-item>
        <el-form-item label="创建时间" prop="buildTime">
          <el-input v-model="form.buildTime" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="修改人" prop="modifiedOperator">
          <el-input v-model="form.modifiedOperator" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="修改日期" prop="modifiedDate">
          <el-input v-model="form.modifiedDate" placeholder="请输入修改日期" />
        </el-form-item>
        <el-form-item label="修改时间" prop="modifiedTime">
          <el-input v-model="form.modifiedTime" placeholder="请输入修改时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPush, getPush, delPush, addPush, updatePush, exportPush } from "@/api/activity/push";

export default {
  name: "Push",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 活动推送表格数据
      pushList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        activityNo: null,
        pushNo: null,
        pushTimeType: null,
        pushTime: null,
        pushStartDate: null,
        pushEndDate: null,
        pushCrowdType: null,
        directPushType: null,
        startRegisterDate: null,
        endRegisterDate: null,
        customerNoPattern: null,
        customerStatus: null,
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询活动推送列表 */
    getList() {
      this.loading = true;
      listPush(this.queryParams).then(response => {
        this.pushList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        activityNo: null,
        pushNo: null,
        pushTimeType: null,
        pushTime: null,
        pushStartDate: null,
        pushEndDate: null,
        pushCrowdType: null,
        directPushType: null,
        startRegisterDate: null,
        endRegisterDate: null,
        customerNoPattern: null,
        customerStatus: "0",
        buildOperator: null,
        buildDate: null,
        buildTime: null,
        modifiedOperator: null,
        modifiedDate: null,
        modifiedTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加活动推送";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPush(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改活动推送";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePush(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPush(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除活动推送编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPush(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有活动推送数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPush(queryParams);
        }).catch(() => {});
    }
  }
};
</script>
